﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Document_Management
{
    public partial class Search程式撰寫人 : Form
    {
        static string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["庫存管理"].ConnectionString;
        private DataGridView GV程式撰寫人代號Search;
        private TextBox txt程式撰寫人代號;
        private Label label1;
        private Button btn_search;
        private Button btn_OK;
        TextBox tb;
        public Search程式撰寫人(TextBox tb)
        {
            InitializeComponent();
            this.tb = tb;
        }

        private void Search程式撰寫人_Load(object sender, EventArgs e)
        {

        }

        private void btn_search程式撰寫人代號_Click(object sender, EventArgs e)
        {

            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                string strcmd = "sp_Search程式撰寫人代號_尋找";
                SqlDataAdapter cmd = new SqlDataAdapter(strcmd, con);
                cmd.SelectCommand.CommandType = CommandType.StoredProcedure;
                if (txt程式撰寫人代號.Text != "") cmd.SelectCommand.Parameters.AddWithValue("@程式撰寫人代號或姓名", txt程式撰寫人代號.Text);
                DataTable dt = new DataTable();
                cmd.Fill(dt);
                GV程式撰寫人代號Search.DataSource = dt;
                PublicClass.setRowNumber(GV程式撰寫人代號Search);
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                con.Close();
            }

        }

        private void GV程式撰寫人代號Search_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(GV程式撰寫人代號Search);
        }

        private void GV程式撰寫人代號Search_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(GV程式撰寫人代號Search);
        }

        private void InitializeComponent()
        {
            this.GV程式撰寫人代號Search = new System.Windows.Forms.DataGridView();
            this.txt程式撰寫人代號 = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.btn_search = new System.Windows.Forms.Button();
            this.btn_OK = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.GV程式撰寫人代號Search)).BeginInit();
            this.SuspendLayout();
            // 
            // GV程式撰寫人代號Search
            // 
            this.GV程式撰寫人代號Search.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.GV程式撰寫人代號Search.Location = new System.Drawing.Point(17, 59);
            this.GV程式撰寫人代號Search.Name = "GV程式撰寫人代號Search";
            this.GV程式撰寫人代號Search.Size = new System.Drawing.Size(265, 162);
            this.GV程式撰寫人代號Search.TabIndex = 0;
            // 
            // txt程式撰寫人代號
            // 
            this.txt程式撰寫人代號.Location = new System.Drawing.Point(115, 26);
            this.txt程式撰寫人代號.Name = "txt程式撰寫人代號";
            this.txt程式撰寫人代號.Size = new System.Drawing.Size(100, 20);
            this.txt程式撰寫人代號.TabIndex = 1;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(14, 29);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(100, 13);
            this.label1.TabIndex = 2;
            this.label1.Text = "程式撰寫人代號 : ";
            // 
            // btn_search
            // 
            this.btn_search.Location = new System.Drawing.Point(222, 25);
            this.btn_search.Name = "btn_search";
            this.btn_search.Size = new System.Drawing.Size(60, 23);
            this.btn_search.TabIndex = 11;
            this.btn_search.Text = "查詢";
            this.btn_search.UseVisualStyleBackColor = true;
            this.btn_search.Click += new System.EventHandler(this.btn_search_Click);
            // 
            // btn_OK
            // 
            this.btn_OK.Location = new System.Drawing.Point(116, 227);
            this.btn_OK.Name = "btn_OK";
            this.btn_OK.Size = new System.Drawing.Size(75, 23);
            this.btn_OK.TabIndex = 13;
            this.btn_OK.Text = "確定";
            this.btn_OK.UseVisualStyleBackColor = true;
            this.btn_OK.Click += new System.EventHandler(this.btn_OK_Click);
            // 
            // Search程式撰寫人
            // 
            this.ClientSize = new System.Drawing.Size(298, 261);
            this.Controls.Add(this.btn_OK);
            this.Controls.Add(this.btn_search);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.txt程式撰寫人代號);
            this.Controls.Add(this.GV程式撰寫人代號Search);
            this.Name = "Search程式撰寫人";
            this.Load += new System.EventHandler(this.Search程式撰寫人_Load_1);
            ((System.ComponentModel.ISupportInitialize)(this.GV程式撰寫人代號Search)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private void Search程式撰寫人_Load_1(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                string strcmd = "sp_Search程式撰寫人代號_尋找";
                SqlDataAdapter cmd = new SqlDataAdapter(strcmd, con);
                cmd.SelectCommand.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                cmd.Fill(dt);
                GV程式撰寫人代號Search.DataSource = dt;
                PublicClass.setRowNumber(GV程式撰寫人代號Search);
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                con.Close();
            }
        }

        private void btn_search_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                string strcmd = "sp_Search程式撰寫人代號_尋找";
                SqlDataAdapter cmd = new SqlDataAdapter(strcmd, con);
                cmd.SelectCommand.CommandType = CommandType.StoredProcedure;
                if (txt程式撰寫人代號.Text != "") cmd.SelectCommand.Parameters.AddWithValue("@程式撰寫人代號或姓名", txt程式撰寫人代號.Text);
                DataTable dt = new DataTable();
                cmd.Fill(dt);
                GV程式撰寫人代號Search.DataSource = dt;
                PublicClass.setRowNumber(GV程式撰寫人代號Search);
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

                con.Close();
            }
        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
            try
            {
                int r = GV程式撰寫人代號Search.CurrentCell.RowIndex;
                string sup程式撰寫人代號Id = GV程式撰寫人代號Search.Rows[r].Cells[0].Value.ToString();
                tb.Text = sup程式撰寫人代號Id;
                this.Close();
            }
            catch
            {

            }
        }


    }
}
